//顶部导航时间
var time = document.querySelector(".time");
var timeControl = null;
timeControl = setInterval(function(){
    var nowTime = new Date();
    var year = nowTime.getFullYear();
    var month = nowTime.getMonth()+1;
    var day = nowTime.getDate();
    var hour = nowTime.getHours();
    var minutes = nowTime.getMinutes();
    time.innerHTML=year+`年`+month+`月`+day+`日`+hour+`:`+minutes;
},1000)
//点击退出返回登录页面
var loginOut = document.querySelector(".loginOut");
loginOut.onclick = function(){
    location.href="../login/login.html"
}
//左侧点击菜单栏显示相应的子菜单 如果有就显示没有则不显示
 var myul = document.querySelector("#myul");
 var lis = myul.querySelectorAll("li");
 var childmenu = myul.querySelectorAll(".childmenu");
for(var i=0;i<lis.length;i++){
    lis[i].onclick = function(){
        for(var j=0;j<lis.length;j++){
            if(this==lis[1]){
                childmenu[0].setAttribute("class","show childmenu");
                childmenu[1].setAttribute("class","show childmenu");
                childmenu[2].setAttribute("class","show childmenu");
                childmenu[3].setAttribute("class","shownone childmenu");
                childmenu[4].setAttribute("class","shownone childmenu");
            }else if(this == lis[9]){
                childmenu[0].setAttribute("class","shownone childmenu");
                childmenu[1].setAttribute("class","shownone childmenu");
                childmenu[2].setAttribute("class","shownone childmenu");
                childmenu[3].setAttribute("class","show childmenu");
                childmenu[4].setAttribute("class","show childmenu");
            }else if(this == lis[0]||this == lis[5]||this == lis[6]||this == lis[7]||this == lis[8]||this == lis[12]){
                childmenu[0].setAttribute("class","shownone childmenu");
                childmenu[1].setAttribute("class","shownone childmenu");
                childmenu[2].setAttribute("class","shownone childmenu");
                childmenu[3].setAttribute("class","shownone childmenu");
                childmenu[4].setAttribute("class","shownone childmenu");
            }
        }
    }
 }
//实现跳转到相应的界面
var arr = ["../class/class.html","../daily/daily.html","../daily/daily-out.html","../daily/daily-rest.html","../daily/daily-total.html","../user/user.html","../student/student.html","../journal/journal.html","../exam/exam.html","../project/project.html","../project/mytask.html","../system/system.html"];
for(var i=0;i<lis.length;i++){
    lis[i].addEventListener("click",function(){
        for(var j=0;j<lis.length;j++){
            if(this == lis[j]){
                // lis[j].firstElementChild.parentElement.style.borderRight="3px solid #0f6ab1"
                location.href = arr[j]
                
            }
        }
    })
}


//用户名
var user = document.getElementsByClassName("user")[0].getElementsByTagName("p")[0];
console.log(user);
user.innerHTML = localStorage.getItem("username");


//角色判断
//左侧点击菜单栏显示相应的子菜单 如果有就显示没有则不显示
var myul = document.querySelector("#myul");
var lis = myul.querySelectorAll("li");
console.log(lis);
var userrole = localStorage.getItem("userrole");
console.log(userrole);
// for(var i=0;i<lis.length;i++){
    if(userrole == "学生"){
        lis[0].setAttribute("class","shownone");
        lis[2].setAttribute("class","shownone");
        lis[5].setAttribute("class","shownone");
        lis[6].setAttribute("class","shownone");
        lis[8].setAttribute("class","shownone");
        lis[1].addEventListener("click",function(){
            console.log(111);
            location.href = "../daily/daily-rest.html"
        })
        lis[9].addEventListener("click",function(){
            console.log(111);
            location.href = "../project/mytask.html"
        })
    }
